package co.fitstart.admin.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.course.CourseType;
import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.course.round.CourseRoundResult;
import co.fitstart.entity.course.round.RoundStatus;
import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.site.Site;

/**
 * 
 * @author haiyan_xiao
 *
 */
@Dynamic("hibernate")
public interface CourseRoundResultDao {

    /**
     * 
     * @param courseRound
     * @return
     */
    @Query("FROM CourseRoundResult WHERE courseRound = :courseRound")
    public CourseRoundResult load(@Variable("courseRound") CourseRound courseRound);

    /**
     * 
     * @param courseStatus
     * @param begin
     * @param end
     * @return
     */
    @Query("SELECT courseRoundResult FROM CourseRoundResult courseRoundResult WHERE courseRoundResult.courseRound.disabled=false AND courseRoundResult.courseRound.courseStatus= :courseStatus AND courseRoundResult.courseRound.finishTime >= :begin AND courseRoundResult.courseRound.finishTime <= :end")
    public List<CourseRoundResult> listCourseRoundResult(@Variable("courseStatus") RoundStatus courseStatus, @Variable("begin") Date begin, @Variable("end") Date end);

    /**
     * 
     * @param courseStatus
     * @param begin
     * @param end
     * @param site
     * @return
     */
    @Query("SELECT courseRoundResult FROM CourseRoundResult courseRoundResult WHERE courseRoundResult.courseRound.disabled=false AND courseRoundResult.courseRound.courseStatus= :courseStatus AND courseRoundResult.courseRound.finishTime >= :begin AND courseRoundResult.courseRound.finishTime <= :end AND courseRoundResult.courseRound.site = :site")
    public List<CourseRoundResult> listCourseRoundResult(@Variable("courseStatus") RoundStatus courseStatus, @Variable("begin") Date begin, @Variable("end") Date end, @Variable("site") Site site);

    /**
     * 
     * @param courseStatus
     * @param begin
     * @param end
     * @param sites
     * @return
     */
    @Query("SELECT courseRoundResult FROM CourseRoundResult courseRoundResult WHERE courseRoundResult.courseRound.disabled=false AND courseRoundResult.courseRound.courseStatus= :courseStatus AND courseRoundResult.courseRound.finishTime >= :begin AND courseRoundResult.courseRound.finishTime <= :end AND courseRoundResult.courseRound.site IN (:sites)")
    public List<CourseRoundResult> listCourseRoundResult(@Variable("courseStatus") RoundStatus courseStatus, @Variable("begin") Date begin, @Variable("end") Date end, @Variable("sites") List<Site> sites);

    /**
     * 
     * @param courseTypes
     * @param courseStatuss
     * @param sites
     * @param coach
     * @return
     */
    @Query("SELECT new Map(courseRound.id AS id, previousPicture AS before, laterPicture AS after) FROM CourseRoundResult WHERE courseRound.disabled = false AND courseRound.courseType IN (:courseTypes) AND courseRound.course.experience = false AND courseRound.courseStatus IN (:courseStatuss) AND courseRound.site IN (:sites) AND courseRound.coach = :coach")
    public List<Map<String, Object>> listContrastPhoto(@Variable("courseTypes") List<CourseType> courseTypes, @Variable("courseStatuss") List<RoundStatus> courseStatuss, @Variable("sites") List<Site> sites, @Variable("coach") Principal coach);

    /**
     * 
     * @param courseTypes
     * @param courseStatuss
     * @param sites
     * @return
     */
    @Query("SELECT new Map(courseRound.id AS id, previousPicture AS before, laterPicture AS after) FROM CourseRoundResult WHERE courseRound.disabled = false AND courseRound.courseType IN (:courseTypes) AND courseRound.course.experience = false AND courseRound.courseStatus IN (:courseStatuss) AND courseRound.site IN (:sites)")
    public List<Map<String, Object>> listContrastPhoto(@Variable("courseTypes") List<CourseType> courseTypes, @Variable("courseStatuss") List<RoundStatus> courseStatuss, @Variable("sites") List<Site> sites);

    /**
     * 
     * @param courseTypes
     * @param courseStatuss
     * @param sites
     * @param coach
     * @return
     */
    @Query("FROM CourseRoundResult courseRoundResult WHERE courseRoundResult.courseRound.disabled = false AND courseRound.courseType IN (:courseTypes) AND courseRound.course.experience = false AND courseRound.courseStatus IN (:courseStatuss) AND courseRound.site IN (:sites) AND courseRound.coach = :coach")
    public List<CourseRoundResult> list(@Variable("courseTypes") List<CourseType> courseTypes, @Variable("courseStatuss") List<RoundStatus> courseStatuss, @Variable("sites") List<Site> sites, @Variable("coach") Principal coach);

    /**
     * 
     * @param courseTypes
     * @param courseStatuss
     * @param sites
     * @return
     */
    @Query("FROM CourseRoundResult courseRoundResult WHERE courseRoundResult.courseRound.disabled = false AND courseRound.courseType IN (:courseTypes) AND courseRound.course.experience = false AND courseRound.courseStatus IN (:courseStatuss) AND courseRound.site IN (:sites)")
    public List<CourseRoundResult> list(@Variable("courseTypes") List<CourseType> courseTypes, @Variable("courseStatuss") List<RoundStatus> courseStatuss, @Variable("sites") List<Site> sites);
}
